<?php
session_start();
header("Content-type: image/PNG"); 
$im = imagecreate(50,20);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im, 200,200,200);
imagefill($im,0,0,$gray);
$authnum=$_SESSION['go_authcode'];
//将四位整数验证码绘入图片
imagestring($im, 5, 7, 3, $authnum, $black);
for($i=0;$i<200;$i++)   //加入干扰象素
{
    $randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
    imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>